<!--倒计时组件-->
<template>
  <span>{{m}}:{{s}}</span>
</template>

<script>
  export default {
    name: 'timeOutComponent',
    props: {
      initSeconds: {
        type: Number,
        default: 0
      }
    },
    data () {
      return {
        timer: null,
        m: 0,
        s: 0
      }
    },
    mounted () {
      console.log(this.initSeconds)
      this.timeCutDown(this.initSeconds)
    },
    methods: {
      timeCutDown (s) {
        s--
        this.m = (Math.floor(s / 60) + '').padStart(2, '0')
        this.s = (s % 60+ '').padStart(2, '0')
        if (s <= 0) {
          this.endTime()
          return false
        }
        this.timer = setTimeout(() => {
          this.timeCutDown(s)
        }, 1000)
      },
      endTime () {
        this.$emit('endTime')
      }
    },
    beforeDestory () {
      clearTimeout(this.timer)
    }
  }
</script>

<style scoped>
</style>
